﻿<!DOCTYPE html>
<html>
<script type="text/javascript" src="js/jquery-2.1.3.js"></script>
<head>
<meta charset="UTF-8">
<title>设备采购订单申请填写</title>

<style type="text/css">
	form{width: 500px;overflow: hidden;margin: 50px auto;}
	div{line-height: 40px;}
	input{width: 250px;padding-left: 10px;height: 30px;
	line-height: 30px;color: #333;font-size: 14px;
	border: 1px solid #666;outline: none;margin-bottom: 10px;display: inline-block;}
	span{display: inline-block;float: left;}
	.submit{width: 120px;background: #666;color: #fff;margin-left:0px;cursor: pointer;}
	#sb_demo input{width: 90px;}
</style>

</head>
<body>

<form action="applyPurchase"  class="form" onsubmit="return check(this)">
	<div><span>申请人：</span><input type="text" name="gly_name" id="gly_name" placeholder="请输入采购订单申请人" /><br /></div>
	<div><span>供应商：</span><input type="text" name="gys_name" id="gys_name" placeholder="请输入供应商：" /><br /></div>
	<div><span>日  期：</span><input type="date" name="applypurchasetime" id="applypurchasetime" placeholder="请输入日期" /><br /></div>						
	<!-- <div><span>确认：</span><input type="password" name="pwd2" id="pwd2" placeholder="确认密码" /><br />	</div>					
	<div><span>邮箱：</span><input type="text" name="email" id="email" placeholder="邮箱" /><br /></div> -->
	<div id="sb_demo"><span>设备名称：</span><span><input type="text" name="sb_name" id="sb_name" placeholder="请输入设备名称" /></span>
	<span>数量：</span><input type="text" name="count" id="count" placeholder="请输入设备数量" /><br />
	</div>
	<input id="addequipment" type="button" value="添加" class="submit" />
	<input type="reset" value="清空" class="submit" />
	<input type="submit" value="提交" class="submit" />
</form>
<script type="text/javascript">
function check(){
//			姓名
		var name = document.getElementById("gly_name");			
		if(name.value==''){
			alert('申请人姓名不能为空');
			name.focus();
			return false;
		}else{
			var vname=(/^[a-zA-Z\u4e00-\u9fa5]{2,10}$/);
			if (!vname.test(name.value)) {
				alert('姓名2-10个字，只能是中文或英文');
				name.focus();
				return false; 
			}
		}	
		
		var name = document.getElementById("gys_name");			
		if(name.value==''){
			alert('供应商名称不能为空');
			name.focus();
			return false;
		}
	
//			电话
		var phone = document.getElementById('phone');
		if(phone.value==''){
			alert('电话不能为空');
			phone.focus();
			return false;
		}else{
			var phone_reg = /^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}|17[0-9]{1}[0-9]{8}$|14[0-9]{1}[0-9]{8}/;
			var tel_reg = /^([0-9]{3,4}-)?[0-9]{7,8}$/;
			if(!phone_reg.test(phone.value) && !tel_reg.test(phone.value)){
				alert('手机或电话号码格式不正确。如果是固定电话，必须形如(xxxx-xxxxxxxx)');
				phone.focus();
				return false;
			}
		}
		
//			密码
		var pwd1 = document.getElementById('pwd1');
		if(pwd1.value==''){
			alert('密码不能为空');
			pwd1.focus();
			return false;
		}else{
			var vpwd = /^[A-Za-z0-9]+$/;
			if(!vpwd.test(pwd1.value)){
				alert('密码错误，密码由数字和字母组成');
				pwd1.focus();
				return false;
			}else{
				if(pwd1.value.length<6){
					alert('密码不能少于6位');
					pwd1.focus();
					return false;
				}
			}
		}
//			验证密码
		var pwd2 = document.getElementById('pwd2');
		if(!(pwd2.value==pwd1.value)){
			alert('确认密码与第一次输入不同，请重新输入');
			pwd2.focus();
			return false;
		}
	
//			邮箱
		var email = document.getElementById('email');
		if(email.value==''){
			alert('邮箱不能为空');
			email.focus();
			return false;
		}else{
			var vemail = /^[0-9a-zA-Z]+(?:[\_\.\-][a-z0-9\-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\.[a-zA-Z]+$/i;
			if(!vemail.test(email.value)){
				alert('邮箱格式错误');
				email.focus();
				return false;
			}
		}
//			地址
		var address = document.getElementById('address');
		if(address.value==''){
			alert('地址不能为空');
			address.focus();
			return false;
		}else{
			if(address.value.length<8){
				alert('不能少于8个字');
				address.focus();
				return false;
			}
		}
		
}
$('#addequipment').click(function(){
		$('#sb_demo').append("<div id='sb_demo'><span>设  备：</span><input type='text'"+
	 	"name='sb_name' placeholder='请输入设备名称' /><br /></div>");
  });
		
</script>


</body>
</html>